import request from '@/utils/request'
import qs from 'qs'

export function initData(url, params, method) {
  if (method.toLowerCase() === 'get') {
    return request({
      url: url + '?' + qs.stringify(params, { indices: false }),
      method: method
    })
  }
  if (method.toLowerCase() === 'post') {
    return request({
      url: url,
      method: method,
      data: params
    })
  }
}

export function download(url, params) {
  return request({
    url: url + '?' + qs.stringify(params, { indices: false }),
    method: 'get',
    responseType: 'blob'
  })
}

export function uploadFile(params) {
  const formData = new FormData()
  formData.append('file', params.file)
  return request({
    url: '/font/uploadByOss',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}
